package cn.waterr.luban.demo.cart.main;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class RpcServer {
    public static void main(String[] args) throws IOException {
        while(true){
            ServerSocket serverSocket = new ServerSocket(8888);
            System.out.println("waiting to connection！");
            Socket socket = serverSocket.accept();
            System.out.println("connection successful!");
            InputStream inputStream = socket.getInputStream();
            DataInputStream dis = new DataInputStream(inputStream);
            String name = dis.readUTF();
            System.out.println("你发给服务端的消息是:"+name);
            HelloServiceImpl helloService = new HelloServiceImpl();
            String message = helloService.sayHi(name);
            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
            dos.writeUTF(message);

        }
    }
}
